package cn.wolfcode.p2p.interceptor;

import cn.wolfcode.p2p.base.util.RequireLogin;
import cn.wolfcode.p2p.base.util.UserContext;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CheckLoginInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                             Object handler) throws Exception {
        if(UserContext.getCurrent() == null){
            //重定向回到登录界面
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }
}
